import request from '../utils/request'

/**
 * 用户登录
 * @param {Object} data - 登录数据 {username, password}
 * @returns {Promise}
 */
export function login(data) {
  return request({
    url: '/auth/login',
    method: 'post',
    data,
    headers: {
      'Content-Type': 'application/json'
    }
  })
}


/**
 * 用户登出
 * @returns {Promise}
 */
export function logout() {
  return request({
    url: '/auth/logout',
    method: 'post',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}

/**
 * 用户注册
 * @param {Object} data - 注册数据 {username, password, phone, email}
 * @returns {Promise}
 */
export function register(data) {
  return request({
    url: '/auth/register',
    method: 'post',
    data,
    headers: {
      'Content-Type': 'application/json'
    }
  })
}

/**
 * 修改密码
 * @param {Object} data - 密码数据
 * @returns {Promise}
 */
export function changePassword(data) {
  return request({
    url: '/user/password',
    method: 'put',
    data
  })
}

/**
 * 重置密码
 * @param {Object} data - 重置密码数据
 * @returns {Promise}
 */
export function resetPassword(data) {
  return request({
    url: '/auth/reset-password',
    method: 'post',
    data
  })
}

// 更新用户信息
export function updateUser(data) {
  return request({
    url: '/user/update',
    method: 'put',
    data
  })
} 

/**
 * 获取用户信息
 * @returns {Promise}
 */

export function getUserInfo() {
  return request({
    url: '/user/info',
    method: 'get',
    headers: {
      Authorization: `Bearer ${localStorage.getItem('token')}`,
      'Cache-Control': 'no-cache'
    }
  })
}